<?php
/**
 * Description: 新品速递-wiki表
 * Created by PhpStorm.
 * User: congyukun
 * Date: 2021/5/19
 * Time: 18:36
 */

namespace Biz\model\NewProduct;

use Hhz\Mysql\BaseDbModel;

class NewProductWikiModel extends BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'new_product_wiki';

    //状态 0:草稿(默认) 1：通过 2：拒绝 5:待审核
    public const STATUS_PASS = 1;
    public const STATUS_DRAFT = 0;
    public const STATUS_REJECT = 2;
    public const STATUS_WAIT = 5;

    //虚拟状态 3:活动中 4：活动结束
    public const STATUS_ACTING = 3;
    public const STATUS_END = 4;

    //删除状态 1：删除 0：默认
    public const DELETED = 1;
    public const NO_DELETED = 0;
    //板块 1:超级新品 2：甄选新品
    public const SUPER_PDT = 1;
    public const GRACE_PDT = 2;

    //系统消息推送状态 0:默认,1:有50%用户填写收货地址,2: 有100%用户填写收货地址
    public const SYSTEM_MSG_PUSH_STATUS_DEFAULT = 0;
    public const SYSTEM_MSG_PUSH_STATUS_ONE = 1;
    public const SYSTEM_MSG_PUSH_STATUS_TWO = 2;


    public const ACT_STATUS = [
        self::STATUS_PASS => "审核通过",
        self::STATUS_WAIT => "待审核",
        self::STATUS_REJECT => "审核未通过",
        self::STATUS_ACTING => "活动中",
        self::STATUS_END => "活动结束",
//      self::STATUS_DRAFT => "草稿",
    ];
    //开奖任务 1:已创建  -1 ：未创建
    public const OPEN_STATUS_CREATED = 1;
    public const OPEN_STATUS_UNCREATED = -1;
    //生成图片状态 1：已生成 2:未生成
    public const CREATED = 1;
    public const UNCREATED = 2;

    public const DYNAMIC_STATUS = [
        self::CREATED => '已生成',
        self::UNCREATED => '未生成',
    ];
    //发动态图片
    public const IMG_ID_GRACE_PDT = '6913030ku0bl0b200qvyj4y';

    /**
     * 获取一行
     * @param $where
     * @param string $field
     * @return array|mixed|null
     */
    public static function first($where, $field = '*')
    {
        $rs = self::get($field, $where);
        if (!$rs) {
            return null;
        }
        return $rs;
    }

    /**
     * 批量查询
     * @param $where
     * @param  $field
     * @return array|bool
     */
    public static function all($where, $field = '*')
    {
        return self::select($field, $where);
    }

    /**
     * 获取一列的值
     * @param $where
     * @param array $field
     * @return array|bool
     */
    public static function pluck($where, array $field = ['id'])
    {
        return self::select($field, $where);
    }

    /**
     * 从记录中获取单个值
     * @param $where
     * @param string $columns
     * @return array|bool
     */
    public static function value($where, string $columns = 'id')
    {
        return self::get($columns, $where);
    }

    /**
     * 连表查询
     * @param $table
     * @param $main_col
     * @param $attach_col
     * @param $field
     * @param $where
     * @return array|bool
     */
    public static function left_join($table, $main_col, $attach_col, $field, $where)
    {
        $join = ['[>]' . $table => [$main_col => $attach_col]];
        return self::select($join, $field, $where);
    }

}